package cms.simmytech.dialect;

import java.util.HashSet;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import cms.simmytech.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.thymeleaf.dialect.AbstractProcessorDialect;
import org.thymeleaf.processor.IProcessor;
import org.thymeleaf.standard.StandardDialect;
import org.thymeleaf.standard.processor.StandardXmlNsTagProcessor;
import org.thymeleaf.templatemode.TemplateMode;

@Component
public class CustomDialect extends AbstractProcessorDialect {

	private static final String NAME = "系统自定义标签";

	private static final String PREFIX = "cms";


	@Autowired
	private UserService userService;
	@Autowired
	private HttpServletRequest request;

	@Value("${simmytech.momentPath}")
	private String webPath;

	@Value("${simmytech.useSSL}")
	private boolean useSSL;

	public CustomDialect() {
		super(NAME, PREFIX, StandardDialect.PROCESSOR_PRECEDENCE);
	}

	@Override
	public Set<IProcessor> getProcessors(String dialectPrefix) {
		Set<IProcessor> processors = new HashSet<IProcessor>();
		processors.add(new RoleCustomDialect(dialectPrefix, userService));
		processors.add(new PermissionNameCustomDialect(dialectPrefix, userService));
		processors.add(new TimeCustomDialect(dialectPrefix));
		processors.add(new PageCustomDialect(dialectPrefix, request, useSSL));
		processors.add(new StandardXmlNsTagProcessor(TemplateMode.HTML, dialectPrefix));
		processors.add(new MomentImgDialect(dialectPrefix, webPath));
		processors.add(new UserPicDialect(dialectPrefix, webPath));
		return processors;
	}

}
